Repository navigation
Kanban #1794: Merge into tables with triggers keeps omitted columns and fires update triggers - #8317
labkey-jeckels wants to merge 10 commits into
Conversation
…ting row Script triggers now get beforeUpdate/afterUpdate with the existing row for merge and replace rows whose key already exists, on lists, sample types, data classes, and study datasets.
…adding_1794 # Conflicts: # api/src/org/labkey/api/dataiterator/ExistingRecordDataIterator.java # list/src/org/labkey/list/ListModule.java # list/src/org/labkey/list/model/ListQueryUpdateService.java
|
|
||
| // Rows routed to update get the whole existing row as oldRow | ||
| di = ExistingRecordDataIterator.createBuilder(di, _target, existingRecordKeyColumnNames, sharedKeys, _target instanceof ExpTable, routeMerge).getDataIterator(context); | ||
| DataIterator before = new BeforeIterator(new CachingDataIterator(di), context, carryForwardColumns); |
There was a problem hiding this comment.
Claude:
nit: on a routed MERGE, dataset and list trigger rows now include the routing lookup's existing-record column, and datasets also get the computed lsid. Probably harmless, since ExpTable triggers already see the former, but worth knowing if any script iterates over row's keys.
There was a problem hiding this comment.
Agreed that this seems harmless. Leaving as-is.
| Object date = dateIndex == null ? null : input.get(dateIndex); | ||
| if (participant != null && (_dsd.isDemographicData() || sequenceNum instanceof Number)) | ||
| { | ||
| return lsid.translateLsid(participant.toString(), sequenceNum instanceof Number n ? n.doubleValue() : null, |
There was a problem hiding this comment.
Claude:
When the input has a Container column, this builds the LSID from it, but dataset import ignores that column unless the study is a dataspace study with TargetMultipleContainers (DatasetDataIteratorBuilder:186-196). If the value isn't the folder's entityId, such as a folder path, the LSIDs never match. The row's trigger then fires beforeInsert with no old row while import updates the existing row.
Reproduced this locally: a MERGE with Container set to the folder path updated the existing row but fired beforeInsert. Could this pass the container only in that dataspace/TargetMultipleContainers case, matching import?
There was a problem hiding this comment.
Fixed, and test case added.
|
|
||
| // The import pipeline doesn't expect an existing record from a lookup made only to route triggers | ||
| boolean routingOnlyLookup = false; | ||
| if (routeMerge && existingRecordKeyColumnNames == null) |
There was a problem hiding this comment.
Manual testing: a blank key in a list MERGE returns 500 when the list has a script trigger
Repro:
- Create a list
MergeBlankKeywith a Text keyKeyand a Text fieldVal, and insert one row withKey = K000. - In an enabled module, add a trigger script
queries/lists/MergeBlankKey.jscontainingfunction beforeInsert(row, errors) {}. - From the browser console in that folder, run:
LABKEY.Query.importData({
schemaName: 'lists', queryName: 'MergeBlankKey', format: 'tsv', insertOption: 'MERGE',
text: 'Key\tVal\nK200\ta\n\tb\nK000\tc',
success: console.log, failure: console.error
});Expected (develop): the row error Missing value for required property: Key on row 2.
Actual (this branch): HTTP 500 "Should not be here". The server log shows PSQLException: No value specified for parameter 3 from ExistingDataIteratorsTableInfo.prefetchExisting. Without the trigger script, this branch returns the expected row error.
The routing lookup added here runs before the list's required-field check. getSelectExistingSql appends the key's ? placeholder before its null check, then continues without binding a value. That bug predates this PR, but lists with triggers didn't reach it before. Checking for null before appending the placeholder fixes it; ExistingDataIteratorsGetRows already returns early.
There was a problem hiding this comment.
Related: a duplicate key hits a similar 500. A list MERGE with a script trigger and K000 twice fails with an assertion error at ExistingRecordDataIterator.get; develop, and the same list without a trigger, return Duplicate key provided: K000. The routing lookup records the duplicate error first, so the import's own lookup skips its prefetch and the after-trigger getMap() reads an empty record. Skipping unmatched keys in the routing-only lookup, instead of adding row errors, would fix both this and the blank-key 500.
There was a problem hiding this comment.
Test cases added and underlying problems fixed.
…adding_1794 # Conflicts: # experiment/src/org/labkey/experiment/ExperimentModule.java
…s see the whole row Merge pads omitted columns with each matched row's stored value instead of leaving them out, so existing triggers that fill or copy omitted columns keep working.
…as row errors Moves the stored-vs-submitted value comparison into ValueUtil for managed-column checks, and consolidates the list and dataset merge tests onto shared helpers.
Rationale
This PR stops merges into tables with trigger scripts from clearing the columns the incoming data leaves out, and makes script triggers treat a merged row that matches an existing row as an update. The GH Issue 1048 fix only disabled merge for the Biologics registry and media tables; Kanban #1794 tracks the general fix. Whether EHR triggers opt out of the update routing is still open on that issue.
Related Pull Requests
Changes